{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ways to Traverse a Grid\n",
    "\n",
    "[The Original Question](https://mp.weixin.qq.com/s/f3p-T-Zvg0CwqLyFX_VpGQ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "Give you 2 integers $n$ and $m$ representing an $n \\times m$ grid, determine the number of ways you can get from the top-left to the bottom-right of the matrix $y$ going only right or down. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "```\n",
    "n = 2\n",
    "m = 2\n",
    "```\n",
    "\n",
    "This should return 2, since the only possible routes are:\n",
    "\n",
    "1. `Down`＋`Right`\n",
    "2. `Right`＋`Down`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "def num_ways(n, m):\n",
    "    # Fill this in.\n",
    "    ways = 1\n",
    "    for k in range(m, n + m - 1):\n",
    "        ways *= k\n",
    "        pass\n",
    "    for k in range(1, min(n, m)):\n",
    "        ways //= k\n",
    "    return ways\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print(num_ways(3, 3))\n",
    "    pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
